﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using PMS.SANY.Util;

namespace PMS.SANY.Entity
{
    /// <summary>
    /// 生产订单工序
    /// </summary>
    public partial class OprSequence : BusEntity
    {
        /// <summary>
        /// 计划编号（生产订单编号）
        /// </summary>
        public string PlanId { get; set; }

        /// <summary>
        /// 工序号
        /// </summary>
        public string OprSequenceNo { get; set; }

        /// <summary>
        /// 顺序号
        /// </summary>
        public string SequenceNo { get; set; }

        /// <summary>
        /// 工序名称
        /// </summary>
        public string OprSequenceName { get; set; }

        /// <summary>
        /// 工序类型
        /// </summary>
        public string OprSequenceType { set; get; }

        /// <summary>
        /// 计划开始时间
        /// </summary>
        public string ScheduledStartDate { set; get; }

        /// <summary>
        /// 计划结束时间
        /// </summary>
        public string ScheduledCompleteDate { set; get; }

        /// <summary>
        /// 工作中心
        /// </summary>
        public string WorkCenter { set; get; }

        /// <summary>
        /// 工作中心描述
        /// </summary>
        public string WorkCenterName { set; get; }

        /// <summary>
        /// 工位
        /// </summary>
        public string WorkStation { set; get; }

        /// <summary>
        /// 工位描述
        /// </summary>
        public string WorkStationName { set; get; }

        /// <summary>
        /// 工序状态
        /// 110	已下达
        /// 120	已派工
        /// 121	派工失败
        /// 125	已接收
        /// 130	进行中
        /// 135	暂停
        /// 140	已完工
        /// 150	已报工
        /// 155	报工失败
        /// 160	取消报工
        /// 170	已删除
        /// </summary>
        public string ProgressStatus { set; get; }

        /// <summary>
        /// 计划工序数量
        /// </summary>
        public decimal Quantity { set; get; }

        /// <summary>
        /// 实际完成数量
        /// </summary>
        public int ActQuantity { set; get; }

        /// <summary>
        /// 预留参数1
        /// </summary>
        public string paramRsrv1 { set; get; }

        /// <summary>
        /// 预留参数2
        /// </summary>
        public string paramRsrv2 { set; get; }

        /// <summary>
        /// 预留参数3
        /// </summary>
        public string paramRsrv3 { set; get; }

        /// <summary>
        /// 预留参数4
        /// </summary>
        public string paramRsrv4 { set; get; }

        /// <summary>
        /// 预留参数5
        /// </summary>
        public string paramRsrv5 { set; get; }

    }

    public partial class OprSequence : BusEntity
    {
        public virtual Plan Plan { set; get; }

        public virtual List<Component> Components { set; get; }

        public virtual List<StationExecuted> Executeds { set; get; }
    }

    /// <summary>
    /// 实体配置
    /// OnModelCreating
    /// </summary>
    public class OprSequenceTypeConfig : BusEntityTypeConfig<OprSequence>, IEntityTypeConfiguration<OprSequence>
    {
        public override void Configure(EntityTypeBuilder<OprSequence> builder)
        {
            base.Configure(builder);

            #region 主外键关系
            builder.HasOne(p => p.Plan).WithMany(p => p.OprSequences).HasForeignKey(p => p.PlanId);
            #endregion

            #region 字段属性:最大长度,是否必需,默认值
            builder.Property(p => p.OprSequenceNo).HasMaxLength(16).IsRequired();
            builder.Property(p => p.SequenceNo).HasMaxLength(12).IsRequired();
            builder.Property(p => p.OprSequenceName).HasMaxLength(300).IsRequired();
            builder.Property(p => p.OprSequenceType).HasMaxLength(20).IsRequired();
            builder.Property(p => p.ScheduledStartDate).HasMaxLength(30);
            builder.Property(p => p.ScheduledCompleteDate).HasMaxLength(30);
            builder.Property(p => p.WorkCenter).HasMaxLength(40).IsRequired();
            builder.Property(p => p.WorkCenterName).HasMaxLength(400);
            builder.Property(p => p.WorkStation).HasMaxLength(24).IsRequired();
            builder.Property(p => p.WorkStationName).HasMaxLength(400);
            builder.Property(p => p.ProgressStatus).HasMaxLength(200).IsRequired();
            builder.Property(p => p.Quantity).HasMaxLength(24).IsRequired();
            builder.Property(p => p.paramRsrv1).HasMaxLength(64);
            builder.Property(p => p.paramRsrv2).HasMaxLength(64);
            builder.Property(p => p.paramRsrv3).HasMaxLength(64);
            builder.Property(p => p.paramRsrv4).HasMaxLength(64);
            builder.Property(p => p.paramRsrv5).HasMaxLength(64);

            #endregion

            #region 备注
            builder.HasComment("生产订单工序");
            builder.Property(p => p.OprSequenceNo).HasComment("工序号");
            builder.Property(p => p.SequenceNo).HasComment("顺序号");
            builder.Property(p => p.OprSequenceName).HasComment("工序名称");
            builder.Property(p => p.OprSequenceType).HasComment("工序类型");
            builder.Property(p => p.ScheduledStartDate).HasComment("计划开始时间");
            builder.Property(p => p.ScheduledCompleteDate).HasComment("计划结束时间");
            builder.Property(p => p.WorkCenter).HasComment("工作中心");
            builder.Property(p => p.WorkCenterName).HasComment("工作中心描述");
            builder.Property(p => p.WorkStation).HasComment("工位");
            builder.Property(p => p.WorkStationName).HasComment("工位描述");
            builder.Property(p => p.ProgressStatus).HasComment("工序状态");
            builder.Property(p => p.Quantity).HasComment("工序数量 ");
            builder.Property(p => p.paramRsrv1).HasComment("预留参数1");
            builder.Property(p => p.paramRsrv2).HasComment("预留参数2");
            builder.Property(p => p.paramRsrv3).HasComment("预留参数3");
            builder.Property(p => p.paramRsrv4).HasComment("预留参数4");
            builder.Property(p => p.paramRsrv5).HasComment("预留参数5");
            #endregion

            #region 种子数据
            #endregion
        }
    }
}
